package com.thinksns.sociax.t4.model;

import com.thinksns.sociax.thinksnsbase.bean.ListData;
import com.thinksns.sociax.thinksnsbase.bean.SociaxItem;
import com.thinksns.sociax.thinksnsbase.exception.DataInvalidException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 类说明：资讯列表
 * Created by Zoey on 2016-04-27.
 */
public class ModelInformationCateList extends SociaxItem {

    private int id;
    private int cid;
    private String subject;
    private String abstracts;
    private int author;
    private String ctime;
    private int hits;
    private String url;
    private String image;
    private String content;
    private int isDel;
    private int isTop;
    private int comment_count;
    private boolean can_comment = true;
    private ListData<ModelComment> comment_info;
    private ModelUser user_info;

    public boolean isCan_comment() {
        return can_comment;
    }

    public void setCan_comment(boolean can_comment) {
        this.can_comment = can_comment;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCid() {
        return cid;
    }

    public void setCid(int cid) {
        this.cid = cid;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getAbstracts() {
        return abstracts;
    }

    public void setAbstracts(String abstracts) {
        this.abstracts = abstracts;
    }

    public int getAuthor() {
        return author;
    }

    public void setAuthor(int author) {
        this.author = author;
    }

    public String getCtime() {
        return ctime;
    }

    public void setCtime(String ctime) {
        this.ctime = ctime;
    }

    public int getHits() {
        return hits;
    }

    public void setHits(int hits) {
        this.hits = hits;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public ModelInformationCateList(JSONObject data) throws DataInvalidException {
        super(data);
        try {
            if (data.has("id")) this.setId(data.optInt("id"));
            if (data.has("cid")) this.setCid(data.optInt("cid"));
            if (data.has("subject")) this.setSubject(data.optString("subject"));
            if (data.has("abstract")) this.setAbstracts(data.optString("abstract"));
            if (data.has("author")) this.setAuthor(data.optInt("author"));
            if (data.has("ctime")) this.setCtime(data.optString("ctime"));
            if (data.has("hits")) this.setHits(data.optInt("hits"));
            if (data.has("url")) this.setUrl(data.getString("url"));
            if (data.has("image")) this.setImage(data.optString("image"));
            if (data.has("content")){
                setContent(data.optString("content"));
            }
            if (data.has("isDel")){
                setIsDel(data.optInt("isDel"));
            }
            if (data.has("isTop")){
                setIsTop(data.optInt("isTop"));
            }
            if (data.has("comment_count")){
                setComment_count(data.optInt("comment_count"));
            }
            if (data.has("user_info")){
                setUser_info(new ModelUser(data.optJSONObject("user_info")));
                setCan_comment("0".equals(user_info.getComment_weibo()));
            }
            if (data.has("comment_info")){
                comment_info = new ListData<>();
                JSONArray array = data.optJSONArray("comment_info");
                if (array != null && array.length() > 0){
                    int length = array.length();
                    ModelComment comment;
                    for (int i = 0; i < length; i++){
                        comment = new ModelComment(array.optJSONObject(i));
                        comment_info.add(comment);
                    }
                }
            }
        }catch (JSONException e){
            e.printStackTrace();
        }
    }

    public ModelInformationCateList() {
        super();
    }

    @Override
    public boolean checkValid() {
        return false;
    }

    @Override
    public String getUserface() {
        return null;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getIsDel() {
        return isDel;
    }

    public void setIsDel(int isDel) {
        this.isDel = isDel;
    }

    public int getIsTop() {
        return isTop;
    }

    public void setIsTop(int isTop) {
        this.isTop = isTop;
    }

    public int getComment_count() {
        return comment_count;
    }

    public void setComment_count(int comment_count) {
        this.comment_count = comment_count;
    }

    public ListData<ModelComment> getComment_info() {
        return comment_info;
    }

    public void setComment_info(ListData<ModelComment> comment_info) {
        this.comment_info = comment_info;
    }

    public ModelUser getUser_info() {
        return user_info;
    }

    public void setUser_info(ModelUser user_info) {
        this.user_info = user_info;
    }
}
